package com.guanyong.services;

import com.guanyong.dao.IVideoBuyLogDaoMapper;
import com.guanyong.model.VideoBuyLogModel;
import com.guanyong.utils.Comm.ResultCode;
import com.guanyong.utils.Comm.ResultObject;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * Created by mxk on 2017/6/23.
 */
@Service
public class VideoBuyLogServices {
    @Autowired
    IVideoBuyLogDaoMapper iVideoBuyLogDaoMapper;

    @Autowired
    ObjectClassTypeService objectClassTypeService;

    //购买 添加订单
    public ResultObject<Integer> AddBuyLog
        (VideoBuyLogModel videoBuyLogModel)
    {
        ResultObject<Integer> resultObject=new ResultObject<Integer>();
        Integer res=-1;
        res =iVideoBuyLogDaoMapper.insert(videoBuyLogModel);
        if (res >-1){

            resultObject.setCode(ResultCode.OperateOk);
        }
        else{
            resultObject.setCode(ResultCode.OperateFail);
            resultObject.setErrorMsg("添加购买记录失败！");
        }
        return resultObject;
    }

    //获取购买的的记录
    public HashMap<String,Object> GetVideoBuyLogList(
            VideoBuyLogModel videoBuyLogModel,
            Integer isoff,
            String btime,
            String etime,
            Integer pno,
            Integer pagesize,
            Integer allcount){
        HashMap<String,Object> hashMap=new HashMap();
        if (allcount<0){
            Integer count=iVideoBuyLogDaoMapper
                    .SelectVideoBuyLogListCount(videoBuyLogModel,isoff,btime,etime);
            hashMap.put("count",count);
        }
        else {
            hashMap.put("count",allcount);
        }
        List<VideoBuyLogModel> filmModelList
                =iVideoBuyLogDaoMapper.SelectVideoBuyLogList(videoBuyLogModel,isoff,btime,etime,(pno-1)*pagesize,pagesize);


        hashMap.put("list",filmModelList);
        return hashMap;
    }

    //判断用户是否为可以观看电影
    public Boolean CheckVideoBuy(String userid,Integer classType,String objectId){
        Boolean isok=false;
        Integer isCheck=iVideoBuyLogDaoMapper.CheckUserIsVip(userid,objectId,classType);
        if (isCheck!=null&& isCheck==1){
            isok=true ;
        }
        return  isok;
    }
}
